package com.jl.basicframework.ui.customizeView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TextView;


import androidx.constraintlayout.widget.ConstraintLayout;

import com.jl.basicframework.R;


/***
 * @author 作者:姜澜
 * 时间:2022/3/11
 * 邮箱:316879104@pp.com
 * 类简述: 自定义功能菜单
 */
public class OperateFunctionView extends ConstraintLayout {

    /**
     * 功能图片
     */
    private ImageView itmImage;

    /**
     * 功能标题
     */
    private TextView tvTitle;

    public OperateFunctionView(Context context) {
        super(context);
        initView(context);
    }

    public OperateFunctionView( Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
        initAttrs(context,attrs);
    }

    public OperateFunctionView(Context context,AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
        initAttrs(context,attrs);
    }

    /**
     * 初始化视图
     */
    public void initView(Context context){
        LayoutInflater.from(context).inflate(R.layout.view_operate_function,this,true);
        itmImage = findViewById(R.id.itmImage);
        tvTitle = findViewById(R.id.tvTitle);
    }

    public void initAttrs(Context context,AttributeSet attrs){
        @SuppressLint("Recycle")
        TypedArray mTypedArray = context.obtainStyledAttributes(attrs,R.styleable.OperateFunctionView);

        tvTitle.setText(mTypedArray.getString(R.styleable.OperateFunctionView_operateTile));
        tvTitle.setTextColor(mTypedArray.getColor(R.styleable.OperateFunctionView_operateTileColor
                ,context.getResources().getColor(R.color.text_black)));

        itmImage.setImageDrawable(mTypedArray.getDrawable(R.styleable.OperateFunctionView_itmImage));

    }
}
